package Utils;

import static Utils.FileOperat.readFile;
/**
 * @author 锄禾
 * @projectName MkPack
 * @description: 获取Crash日志
 */
public class GetCrash {
    public static String LogCatPath;
    public static String ReportPath;
    public static String MailList;
    public static String CrashResult;
    public static String LogCatFile = "/" + "logcat.log";
    public static String isCrash = "本次允许Monkey发现Crash！";
    public static String notCrash = "本次运行Monkey未发现Crash";

    public GetCrash(String LogcatFolder, String mailList, String reportPath){
        LogCatPath = LogcatFolder + LogCatFile;
        ReportPath = reportPath;
        MailList = mailList;
    }

    /**
    　* @description: 获取crash，并发送邮件
    　* @param
    　* @return
    　*/
    public void getCrash(){
        String logInfo = readFile(LogCatPath);
        if ((logInfo.contains("CrashReport") && logInfo.contains("Bugly")) || logInfo.contains("ANR")
                || logInfo.contains("anr") || logInfo.contains("No Response")){
            CrashResult = isCrash;
        }else {
            CrashResult = notCrash;
        }
        new SendMail().sendMail(MailList,ReportPath,CrashResult);
    }
}
